addpath('../lib');
addpath('../mockData');

disp('initial computations');


niter = 150;

tries = 100;

t = 0:0.3:10; %laikas
lam = 100:1.4:700; %bangos ilgiai

disp(size(t));
disp(size(lam));

W = MockWGaussian(lam);
H = MockHSimple(t);

duomenys=W*H;

R = 3;
%% standart NMF
disp('Computing NMF');
rezD = [];
rezE = [];
for i=1:tries,
    [W1 H1] = NMF(duomenys, R, niter);
    rezE = [rezE EuclidDistWH(W, H, W1, H1)];
    rezD = [rezD DivergWH(W, H, W1, H1)];
end

nmfD = rezD;
nmfE = rezE;

nmfEMean = mean(rezE);
nmfEStd = std(rezE);

nmfDMean = mean(rezD);
nmfDStd = std(rezD);


    fontSize = 26;
h = figure('visible','off');
    
    set(h, 'DefaultLineLineWidth', 1.5);
    set(h, 'DefaultAxesFontSize', fontSize);
    set(h, 'DefaultAxesLineWidth', 1.5);
    plot(1:length(rezE), rezE);
    xlabel('Iteracijos', 'FontSize', fontSize);
    ylabel('Euklidinis atstumas', 'FontSize', fontSize);
    SaveFigure(h, 'NmfEuclidDist');

PlotMisc(1:length(rezD), rezD, 'NmfDivergDist');

disp('Computing CNMF');
rezD = [];
rezE = [];

alpha = 0.5;
beta = 0.5;

for i=1:tries,
    [W1 H1] = CNMF(duomenys, R, niter, alpha, beta);
    rezE = [rezE EuclidDistWH(W, H, W1, H1)];
    rezD = [rezD DivergWH(W, H, W1, H1)];
end

cnmfD = rezD;
cnmfE = rezE;

cnmfEMean = mean(rezE);
cnmfEStd = std(rezE);

cnmfDMean = mean(rezD);
cnmfDStd = std(rezD);

disp('Computing LSNMF');
rezD = [];
rezE = [];
for i=1:tries,
    [W1 H1] = LSNMF(duomenys, R, niter);
    rezE = [rezE EuclidDistWH(W, H, W1, H1)];
    rezD = [rezD DivergWH(W, H, W1, H1)];
end

lsnmfD = rezD;
lsnmfE = rezE;

lsnmfEMean = mean(rezE);
lsnmfEStd = std(rezE);

lsnmfDMean = mean(rezD);
lsnmfDStd = std(rezD);

disp('Computing KLNMF');
rezD = [];
rezE = [];
for i=1:tries,
    [W1 H1] = KLNMF(duomenys, R, niter);
    rezE = [rezE EuclidDistWH(W, H, W1, H1)];
    rezD = [rezD DivergWH(W, H, W1, H1)];
end

klnmfD = rezD;
klnmfE = rezE;

klnmfEMean = mean(rezE);
klnmfEStd = std(rezE);

klnmfDMean = mean(rezD);
klnmfDStd = std(rezD);



disp('Finished');

disp('Euclid');
disp('NMF');
fprintf('Mean: %8.1f, Std: %8.1f\n', nmfEMean, nmfEStd);

disp('CNMF');
fprintf('Mean: %8.1f, Std: %8.1f\n', cnmfEMean, cnmfEStd);

disp('KLNMF');
fprintf('Mean: %8.1f, Std: %8.1f\n', klnmfEMean, klnmfEStd);

disp('LSNMF');
fprintf('Mean: %8.1f, Std: %8.1f\n', lsnmfEMean, lsnmfEStd);



disp('KL');
disp('NMF');
fprintf('Mean: %8.1f, Std: %8.1f\n', nmfDMean, nmfDStd);

disp('CNMF');
fprintf('Mean: %8.1f, Std: %8.1f\n', cnmfDMean, cnmfDStd);

disp('KLNMF');
fprintf('Mean: %8.1f, Std: %8.1f\n', klnmfDMean, klnmfDStd);

disp('LSNMF');
fprintf('Mean: %8.1f, Std: %8.1f\n', lsnmfDMean, lsnmfDStd);

